package com.mark.vo;

import com.mark.pojo.Product;
import com.mark.util.DateTimeUtil;
import com.mark.util.PropertiesUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;

/**
 * Created by Mark on 2018/3/26.
 * 商品Vo类设计
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ProductListVo {
    private Integer id;                 //商品ID
    private Integer categoryId;         //商品种类ID
    private Integer ownerId;            //商品出售者ID
    private String ownerName;           //商品出售者名称
    private String productName;         //商品名称
    private String productSubtitle;     //商品子标题
    private String mainImage;           //商品售价
    private BigDecimal normalPrice;     //商品原价
    private BigDecimal promotionPrice;  //商品售价
    private Integer productStock;       //商品的库存量
    private String enableStatusDes;     //商品状态描述
    private Integer enableStatus;       //商品状态
    private String imageHost;           //访问图片的主机地址
    private String createTime;          //商品的创建时间

    public ProductListVo assembleProductListVo(Product productItem, String ownerName) {//组装Vo对象
        ProductListVo productListVo = new ProductListVo();
        productListVo.setId(productItem.getId());
        productListVo.setOwnerId(productItem.getOwnerId());
        productListVo.setOwnerName(ownerName);
        productListVo.setCategoryId(productItem.getCategoryId());
        productListVo.setProductName(productItem.getProductName());
        productListVo.setMainImage(productItem.getMainImgAddr());
        productListVo.setProductSubtitle(productItem.getProductSubtitle());
        productListVo.setNormalPrice(productItem.getNormalPrice());
        productListVo.setPromotionPrice(productItem.getPromotionPrice());
        productListVo.setProductStock(productItem.getProductStock());
        String enableStatusDes = this.assembleStatus(productItem.getEnableStatus());
        productListVo.setEnableStatusDes(enableStatusDes);
        productListVo.setEnableStatus(productItem.getEnableStatus());
        productListVo.setCreateTime(DateTimeUtil.dateToStr2(productItem.getCreateTime()));
        productListVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix",PropertiesUtil.FTP_SERVER_HTTP_PREFIX));
        return productListVo;
    }

    private String assembleStatus(Integer enableStatus) {//组装商品的状态
        switch (enableStatus){
            case -1 : return "已下架";
            case 0 : return "不合格" ;
            case 1 : return "待审核";
            case 2 : return "出售中";
            default: return "不明确";
        }
    }
}
